Skip to content

perf: cut server, database, relay, and web hot-path overhead - #1095

Merged
badcuban merged 6 commits into
mainfrom
chore/perf-apps-performance-audit
Nov 25, 2026
Merged

badcuban merged 6 commits into
mainfrom
chore/perf-apps-performance-audit

Conversation

@badcuban

Copy link
Copy Markdown
Collaborator

Problem

High-frequency streaming, background polling, SQLite projection writes, and retained web store state accumulated main-thread stalls, redundant git and CLI spawns, and steady memory growth across long sessions.

Changes

  • Server and SQLite (aee8bc705): route streaming content.delta events through a narrow getThreadIngestionContext query instead of 4-query getThreadShellById, update only updated_at on streaming assistant deltas, skip directory scans in ProviderService.listSessions() when no sessions are active, drop redundant SQLite indexes in migration 126, narrow move/setup/assistant-event queries, and scan Claude partial tool JSON incrementally.
  • Web and desktop (e6d177125): cache per-block markdown file-link scans so settled blocks keep stable memo keys while streaming, stabilize empty file-link maps and timeline work rows without Equal.equals, avoid unnecessary toSorted copies on in-place activity upserts, narrow sidebar and inbox store subscriptions, throttle desktop CDP previews and status indicator redraws, and move desktop tray/icon setup off startup.
  • Checkpoints, WebSocket fanout, memory, and async writes (d77f0e446): hand off pre-turn checkpoints between ProviderCommandReactor and CheckpointReactor, shard checkpoint capture per thread, share one coalesced shell stream producer across WebSocket clients with bounded queues, release evicted thread detail slices and derivation caches in the web store, create streaming reveal observers lazily with zero idle animation frames, and move rotating log sinks and usage cache writes to fs.promises.
  • Polling, relay framing, git spawns, and runtime (f55adc23e): remove redundant buffer copies in relaySecure.ts, slow polling 6x for disabled providers, cache Claude version lookups and project favicon probes, cut git status spawns (5 to 3 on clean repos, 5 to 4 local and 10 to 9 remote on dirty repos), make the device MJPEG parser and search ranker linear time, and move DiffWorkerPoolProvider to a dynamic import.

Benchmark highlights (main 7d1a878cd vs f55adc23e)

Workload Before After Change
ProviderService.listSessions (20 calls, 900 rows) 284.79 ms 0.87 ms 327x
Device MJPEG stream parser (10 x 200 KB frames) 216.71 ms 3.40 ms 63.7x
Rotating log sink main-thread block (1,000 lines) 20.32 ms 0.43 ms 47.3x
Project favicon lookup (50 calls, miss / found) 45.27 / 13.45 ms 1.43 / 1.96 ms 31.7x / 6.9x
SQLite delta ingestion lookup (200 calls) 44.44 ms 3.07 ms 14.5x
Search ranking (5 queries x 2,000 messages) 7.95 ms 0.94 ms 8.5x
Timeline work-row stability diff (100 passes x 600 entries) 160.89 ms 22.90 ms 7.0x
Streaming markdown file-link pre-pass (40 blocks) 10.50 ms 1.82 ms 5.8x
Claude partial tool input estimator (514 chunks) 17.56 ms 3.47 ms 5.1x
Git clean local status (per call) 30.01 ms (5 spawns) 18.14 ms (3 spawns) 1.65x
SQLite streaming projection (400 events) 146.15 ms 91.98 ms 1.59x
Evicted thread store memory (25 loaded, 20 evicted) 4,083 KB 819 KB -80%

Verification

  • vp fmt, vp lint, and vp run typecheck pass across all packages.
  • Targeted and affected server, shared, client-runtime, and desktop unit test suites pass.
  • Full web browser test suite passes (118 files, 1,215 tests).

High-rate streaming deltas, session sweeps, and projection writes were triggering redundant SQLite reads, full-row JSON rewrites, and repeated full read-model hydrations on the main thread.

- Return early in ProviderService.listSessions when no adapters are active and fetch bindings only for active session thread IDs.
- Route content.delta runtime ingestion through a narrow active-thread lookup (session and live side-turns) instead of four-query shell hydration with diff-stat rollups.
- Update only updated_at in ProjectionPipeline for assistant messages and activities, guard subagent roster reads behind activityMayAffectSubagents, skip streaming session lookups and no-op turn upserts, and drop redundant correlated subqueries from message upserts.
- Guard Claude partial tool JSON decoding with outer-brace checks, enforce the 500 ms file-change estimate throttle before scanning, and scan partial JSON strings in linear-time slices.
- Scope shell snapshot diff-stat rollups to active or archived threads and replace non-engine getCommandReadModel calls in ProjectSetupSource, LinkMoves, and single-thread ThreadMoves paths.
- Drop six unused or prefix-redundant SQLite indexes in migration 126 and tune NodeSqliteClient with a 1024-entry statement cache, borrower-based statement execution, prepared transaction controls, and savepoint release.
- Wake AssistantEvents discovery only on events that produce assistant actions, and nudge discovery on stale settlements.
Streaming turns and composer typing triggered redundant markdown parses, full-thread UI syncs, duplicated inbox derivations, and broad store re-renders in the web client, while the desktop app serialized shell probing ahead of startup, rasterized all 38 macOS tray icons upfront, and kept preview browser CDP buffers and accessibility active.

Stabilize markdown link-kind state, cache per-block file-path scans, narrow backdrop observers on active chat threads, deduplicate thread shells structurally on modelSelection, switch thread upserts to single-thread UI sync, share one inbox derivation with narrower component selectors, overlap desktop shell probing with startup, rasterize macOS tray frames lazily on first use, and disable unused preview CDP response buffering and eager accessibility tracking.
…s async

Reduces checkpoint git overhead, WebSocket fanout work, retained evicted thread memory, idle reveal animation frames, and blocking main-thread log and cache writes.

- Coordinate pre-turn checkpoints across ProviderCommandReactor and CheckpointReactor, shard checkpoint work across threads with per-checkout revert serialization, and cache stable git lookups in scratchIndex.
- Share one coalesced shell stream producer across WebSocket clients, bound shell and thread subscriber queues with clean resync on overflow, and return only the sequence on event store appends.
- Release evicted thread detail slices and derivation caches while pausing idle eviction offline and preserving pending scroll anchors and worktree locks.
- Create streaming text reveal observers lazily, stop idle animation frames when caught up, and advance only the live reveal tail.
- Move rotating trace and provider logs to fs.promises with per-path rotation locks and shutdown flush, batch desktop child logs, optimize terminal ANSI scans and output bursts, compact usage rate caches, and debounce usage scan cache writes.
Reduces background polling, process spawns, memory retention, and hot-path work across server, web, desktop, shared, and client-runtime without changing user-visible behavior.

- Relay: pass fixed ArrayBuffer views directly to WebCrypto, build header-prefixed records in one allocation, and avoid double-copying single-part frames.
- Providers: slow disabled provider scheduled refreshes by 6x, cap refreshAll concurrency to 3, cache scheduled Claude token usage within the same UTC day, and cache claude --version by resolved executable stat metadata.
- Git and workspace: skip numstat diffs on clean status checks, reuse status GitConfigSnapshot in GitManager, cap background remote refreshes to 4 with post-permit re-checks, and filter ignored tracked files via git ls-files --cached --ignored.
- Pull requests: raise viewer and repository cache capacities to 64, run authored searches in parallel with workspace listings, share worktree listings per sweep with fresh revalidation before auto-merge, and back off confirmed missing worktrees.
- Server and client cleanups: cache ProjectFaviconResolver lookups, stop retaining raw SDK messages in ClaudeAdapter turnState.items, tag OpenCode and ACP streaming chunks as stream fragments, cache compiled search regexes, track MJPEG scan cursors, replace Equal.equals on work rows, skip redundant activity sorts, lazy-load DiffWorkerPoolProvider, pause the desktop backdrop CPU watchdog when art is still or hidden, and cache mainFrameId in PreviewAutomation.
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
threadlines Skipped Skipped Nov 25, 2026 6:17am UTC

Request Review

Wait for RotatingFileSink.writeAsync to settle and for the flush fiber to reschedule before advancing TestClock in packages/shared/src/observability.test.ts, preventing the CI timeout race when async fs.promises calls finish after the test probe triggers.

Group initial vendor and shared startup modules in apps/web/vite.config.ts using $initial and entriesAware rules so startup drops from 96 JS files to 8 files and stays 30 KB under the 915 KB gzip budget.
@badcuban
badcuban added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 700486b Nov 25, 2026
25 checks passed
@badcuban
badcuban deleted the chore/perf-apps-performance-audit branch November 25, 2026 06:31

This branch was previously deployed

1 inactive deployment
Preview — eebd0594 Deployed Nov 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant